/******************************************************************************
* @file     zone_fatal.h
* @brief   关键数据分区处理
* @version  1.0
* @date     2017-01-05
* @author   hickey.liao
* 
* Copyright(C) 2017 Queclink CO.,Ltd.
* All rights reserved.
*
*******************************************************************************/
#ifndef _FATAL_DISCRETE_H
#define _FATAL_DISCRETE_H
#include "aadl/aadl.h"
#include "aadl/flash.h"

#define SECTOR_SIZE           (fchip.sector_size)   /*扇区大小, 单位byte*/
#define BLOCK_SIZE           (fchip.block_size)   /*块大小,单位byte*/
#define CHIP_CAPACITY           (fchip.capacity)   /*FLASH 芯片大小,单位byte*/

#define SECTOR_MASK           (SECTOR_SIZE - 1)              /*扇区掩码 ------*/
#define SECTOR_BASE(addr)     (addr & (~SECTOR_MASK))        /*扇区的基地址 --*/
#define SECTOR_OFFSET(addr)   (addr & SECTOR_MASK)           /*扇区内的偏移 --*/

#define DISCETE_BACKUP_EN   0   /*使能离散存储区备份*/

int fatal_discrete_erase(int zone_id, aadl_option option_set, unsigned int timeout);
int fatal_discrete_init(int zone_id, struct flash_data *data, size_t count);
int fatal_discrete_write(int zone_id, int data_id, void *buf);
int fatal_discrete_read(int zone_id, int data_id, void *buf);
int aad_flash_dir_init(int zone_id);
int aad_flash_dir_erase(int zone_id, aadl_option option_set, unsigned int timeout);
int aad_flash_frequency_init(int zone_id, uint32_t size, uint32_t asize);
int aad_flash_frequency_clear(int zone_id,aadl_option option_set, unsigned int timeout);
int aad_flash_circular_clear(int zone_id, aadl_option option_set, unsigned int timeout);
int aad_flash_circular_init(int zone_id);
int aad_flash_file_init(int zone_id);
void freq_clr_table(void);
void file_clr_table(void);
void fatal_discrete_clr_table(void);
void circular_clr_table(void);
uint32_t fd_estimate_size(fzone_type type, const struct flash_data *data, size_t count);

#endif
